package com.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Case;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.web.model.User;
import com.web.model.dto.UserDto;
import com.web.service.UserService;

@RestController
@RequestMapping("/user")
public class UserAction {

	@Autowired
	UserService userService;

	// @RequestMapping(value={"/selectUserById"}, method=RequestMethod.GET)
	// public User selectUserById(int userId){
	// User user = userService.getUser(userId);
	// return user;
	// }

	@RequestMapping(value = { "/query" }, method = RequestMethod.GET)
	public User selectUserById(HttpServletRequest request) {
		String userId = request.getParameter("id");
		User user = userService.getUser(Integer.valueOf(userId));
		return user;
	}
	
	@RequestMapping(value = { "/queryName" }, method = RequestMethod.GET)
	public User queryName(HttpServletRequest request) {
		String userName = request.getParameter("name");
		User user = userService.queryName(userName);
		return user;
	}
	
	/**
	 * 测试报文
	 */
	@RequestMapping(value = { "/process" }, method = RequestMethod.POST)
	public void processUser(@RequestBody UserDto userDto){
		if (userDto.getProcessType().equals("A"))
			userService.addUser(userDto);
		if (userDto.getProcessType().equals("U"))
			userService.updateUser(userDto);
		if (userDto.getProcessType().equals("D"))
			userService.deleteUser(userDto);
		if (userDto.getProcessType().equals("Q")){
			List<User> list = userService.queryUser(userDto);
			System.out.println("query end");
		}
		System.out.println("process end");
	}
}
